import Vue from 'vue';
import VueI18n from 'vue-i18n';
import Element from 'element-ui'

Vue.use(VueI18n);

// 引入语言包文件
import en from './assets/locales/en.json';
import zh from './assets/locales/zh-CN.json';
// 兼容elementui
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'

// 定义语言包
const messages = {
  en: { ...en, ...enLocale },
  zh: { ...zh, ...zhLocale }
};

let locale = localStorage.getItem('i18nLocale') || 'zh'

// 创建i18n实例
const i18n = new VueI18n({
  locale, // 默认语言
  messages
});

Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})

export default i18n;    